//
//  CQNewCell.swift
//  weibo
//
//  Created by chengqiang on 16/7/22.
//  Copyright © 2016年 chengqiangBiaodashi. All rights reserved.
//

import UIKit

class CQNewCell: UICollectionViewCell {
    
    var image:UIImage?{
        didSet{
            backimagView.image=image
        }
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
        
    }
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func showButton(isShow:Bool)  {
        startBtn.hidden = !isShow
        sharedButton.hidden = !isShow
    }
    
    private func setupUI(){
        self.contentView.addSubview(backimagView)
        self.contentView.addSubview(startBtn)
        self.contentView.addSubview(sharedButton)
        backimagView.snp_makeConstraints { (make) -> Void in
            make.edges.equalTo(self.contentView)
        }
        
        startBtn.snp_makeConstraints { (make)-> Void in
            make.centerX.equalTo(self.contentView)
            make.bottom.equalTo(self.contentView).offset(-160)
        }
        sharedButton.snp_makeConstraints { (make)-> Void in
            make.centerX.equalTo(self.contentView)
            make.bottom.equalTo(startBtn.snp_top).offset(-16)
        }
        
    }
    //背景图片
    private lazy var backimagView:UIImageView = UIImageView(image: UIImage(named: "new_feature_1"))
    
    //勾选按钮
    private lazy var   sharedButton:UIButton={
       let button = UIButton(type: UIButtonType.Custom)
        button.setTitle("分享给大家", forState: UIControlState.Normal)
        button.setImage(UIImage(named:"new_feature_share_false"), forState: UIControlState.Selected)
        button.setImage(UIImage(named:"new_feature_share_true"), forState: UIControlState.Normal)
        
        button.setTitleColor(UIColor.blackColor(), forState: UIControlState.Normal)
        
        button.addTarget(self, action: "sgaedBtnClick", forControlEvents: UIControlEvents.TouchUpInside)
        
        
        return button
    }()
    @objc private func sgaedBtnClick(){
        sharedButton.selected = !sharedButton.selected
    }
    
    
    //开始按钮
    private lazy var startBtn:UIButton={
       let button = UIButton(type: UIButtonType.Custom)
        button.setTitle("开始体验", forState: UIControlState.Normal)
        button.setBackgroundImage(UIImage(named:"new_feature_finish_button"), forState: UIControlState.Normal)
        button.setBackgroundImage(UIImage(named:"new_feature_finish_button_highlighted"), forState: UIControlState.Highlighted)
        button.addTarget(self, action: "startButtonClick", forControlEvents: UIControlEvents.TouchUpInside)
        return button
        
    }()
    @objc private func startButtonClick(){
        AppDelegate.switchRootViewController(CQMianController())
    }
}
